﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cDevWorkflow.cDevDecisionEngine;

namespace TestCustomStep
{
   public class clsRandom100 : deIStep
   {
      public clsStepReturn execute(clsEngineContext oEngineContext)
      {
         int iMiddlePoint = 50;

         clsStepReturn oRet = new clsStepReturn("True", stepState.complete);

         string sMiddlePointPropertyVal = oEngineContext.getProcessedProperty("midPoint").ToString();

         if (!int.TryParse(sMiddlePointPropertyVal, out iMiddlePoint))
         {
            oEngineContext.executingIteration.addMessage("error", "Error converting the mid point value");
            oRet.returnVal = "False";
            oRet.stepState = stepState.error;
            return (oRet);
         }

         Random oRandom = new Random(1);

         if (oRandom.Next(100) > iMiddlePoint)
         {
            oRet.returnVal = "True";
            return(oRet);
         }
         else
         {
            oRet.returnVal = "False";
            return (oRet);
         }
      }
   }
}
